from afast_core.core_tools import json_helper
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.services.service_businesses import \
    Businesses



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    pass
    appid:str
    si_number:str
    dc_number:str



class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam = Depends(),
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class DoctorStationRuleInfoController(IController):

    def business_login(self):
        pass


        def addurlimge(v):
            v['icon'] = v.get("icon") if v.get("icon") and v.get("icon").startswith(
                'http') else ('暂无医生图像' if not v.get("icon") else f'http://infirmary.wohuayuan.com{v.get("icon")}')
            return v
        result  = [addurlimge(v) for v in Businesses.get_doctor_station_rule_info(appid=self.schema_param.appid,
                                                                  dc_number=self.schema_param.dc_number,
                                                                  si_number=self.schema_param.si_number,
                                                                  )]
        if result:

            rule_for_doctor_mode = result[0].get('mode')
            rule_for_doctor_str = result[0].get('mode_workcycle_rules')
            # 获取当前时段内医生的排班列表信息
            if not rule_for_doctor_str:
                self.response_ok = False
                self.response_msg = "当前医生所属医院规则配置信息为空！！！"
                return

            # 如果配置规则存在，且是模式1
            if rule_for_doctor_mode and rule_for_doctor_mode == 1:
                pass
                workcycle_rules_config = json_helper.json_to_dict(rule_for_doctor_str)
                return {**{
                    "name": result[0].get('name'),
                    "icon": result[0].get('icon'),
                    "si_name": result[0].get('si_name'),
                    "rulesname":result[0].get('rulesname'),
                    "rulesid":result[0].get('rulesid'),
                    "worktab": result[0].get('worktab'),
                    "mode": result[0].get('mode'),
                }, **workcycle_rules_config,**self.schema_param.dict()}


